console.show();

path = "/storage/emulated/0/backups/apps/";
path= dialogs.rawInput("请输入软件备份到哪里,带/",path);

mPacManager = context.getPackageManager();

packages = mPacManager.getInstalledPackages(0);
for (i = 0; i < packages.size(); i++) {
    pi = packages.get(i);
    ai = new AppInfo();
    ai.packageName = pi.packageName;
    ai.appName = pi.applicationInfo.loadLabel(mPacManager).toString();
    ai.appIcon = pi.applicationInfo.loadIcon(mPacManager);

    appDir = context.getPackageManager().getApplicationInfo(ai.packageName, 0).sourceDir;

    if (appDir.startsWith("/data")) {
        log(ai.appName);
        files.copy(appDir, path + ai.appName + i + ".apk");

    } else {
        console.info(ai.appName)
    }
}

function AppInfo() {
    // 软件名称
    appName = "";
    // 软件包名
    packageName = "";
    // 软件图标
    appIcon = null;
}

log(packages.size());
